package Event.lib;

import Creature.Player;
import Event.Story;
import Interface.Play0;
import Item.Item;
import acm.util.RandomGenerator;
import java.util.ArrayList;


public class CrazyDog extends Story {
    public CrazyDog(Player player){
        super(player);
        this.options = new String[]{"攻击","打开背包","技能","逃跑"};//
        this.eventName = "Itemmon:crazyDog";
        this.happenText = "你的面前出现了一只瘦弱的狗，看起来饿了好几天了，它现在想要攻击你，你要怎么做？";

    }

    @Override
    public void eventHappen(int option) {

        switch (option) {
            case 0:
                new Play0("src/Interface/狗叫声.mp3").start();
                endText = "狗狗这么可爱你怎么可以攻击狗狗";
                child=new AttackDog(player);
                break;
            case 1:
                endText = "你打开了背包";
                child=new OpenBag(player);
                break;
            case 2:
                endText = "使用技能。";
                child=new YourSkill(player);
                break;
            case 3:
                endText = "你成功逃跑了。但是，由于你不认识路，你绕了一圈又回到了原地。";
                child=new HowOldAreYou(player);
                break;
        }
    }


}
class AttackDog extends CrazyDog{
    public AttackDog(Player player){
        super(player);
        this.options = new String[]{"跳一支舞来安抚一下它"};//
        this.eventName = "CrazyDog";
        this.happenText = "你发现自己不能攻击，挠了挠头，尴尬地笑了笑了。";

    }

    @Override
    public void eventHappen(int option) {
        switch (option) {
            case 0:
                endText = "狗狗不理解你为什么要跳舞，扑上来就是一顿撕咬。你掉了15滴血.....你被送到了一个没听过的私立医院，躺了好1天，付了200快大洋。一段时间过后，你饿了,出来觅食。";
                player.setHealth(player.getHealth()-15);
                player.setMoney(player.getMoney()-200);
                player.setHungry(player.getHungry()-10);

                child = new HowOldAreYou(player);
        }
    }
}
class HowOldAreYou extends CrazyDog{
    public HowOldAreYou(Player player){
        super(player);
        this.options = new String[]{"攻击","打开背包","技能","逃跑"};//
        this.eventName = "HowOldAreYou";
        this.happenText = "于是，你又遇上了之前那条狗，看起来饿了好几天了，它现在想要攻击你，你要怎么做？”";
    }
    public void eventHappen(int option) {
        switch (option) {
            case 0:
                endText = "狗狗这么可爱你怎么可以攻击狗狗";
                child=new AttackDog(player);
                break;
            case 1:
                endText = "你打开了背包";
                child = new OpenBag(player);
                break;
            case 2:
                endText = "你成功想起了你学过的技能。";
                child=new YourSkill(player);
                break;
            case 3:
                endText = "你成功逃跑了。但是，由于你不认识路，你绕了一圈又回到了原地。";
                child=new HowOldAreYou(player);
                break;
        }
    }
}
class YourSkill extends CrazyDog{
    public static final String[] SHAPES = {"石头", "剪刀", "布"};
    RandomGenerator randomGenerator = RandomGenerator.getInstance();

    public String printWinMessage(String yourShape, String computerShape) {
        return("你赢了！" + "你出的是『" + yourShape + "』，狗狗过出的是『" + computerShape + "』。");
    }

    /**
     * 打印输掉的信息
     * @param yourShape         你出的手势
     * @param computerShape     电脑出的手势
     */
    public String printLoseMessage(String yourShape, String computerShape) {
        return ("你输了！" + "你出的是『" + yourShape + "』，狗狗出的是『" + computerShape + "』。");
    }

    /**
     * 打印平局信息
     * @param shape             你跟电脑的手势，应该是一样的，所以平局
     */
    public String printTieMessage(String shape) {
        return ("平局。你和狗狗出的都是『" + shape + "』。");
    }

    public YourSkill(Player player){
        super(player);
        this.options = new String[]{"石头","剪刀","布","逃跑"};//
        this.eventName = "YourSkill";
        this.happenText = "狗狗似乎也做好的战斗的准备。”";
    }
    public void eventHappen(int option) {

        int index = randomGenerator.nextInt(0, 2);
        String computerShape = SHAPES[index];
        switch (option) {
            case 0:
                String yourShape = "石头" ;
                if (computerShape.equals("剪刀")) {
                    endText = printWinMessage(yourShape, computerShape)+"但似乎狗狗并不愿放你走。";
                } else if (computerShape.equals("布")) {
                    endText = printLoseMessage(yourShape, computerShape)+"狗狗得意地给了你一嘴巴子,生命值-1，示意继续。";
                    player.setHealth(player.getHealth()-1);
                } else {
                    endText = printTieMessage(yourShape)+"狗狗并不愿放你走。";
                }
                child = new YourSkill(player);
                break;
            case 1:
                yourShape ="剪刀";
                if (computerShape.equals("布")) {
                    endText = printWinMessage(yourShape, computerShape)+"但似乎狗狗并不愿放你走。";
                } else if (computerShape.equals("石头")) {
                    endText = printLoseMessage(yourShape, computerShape)+"狗狗得意地给了你一嘴巴子,生命值-1，示意继续。";
                } else {
                    endText = printTieMessage(yourShape)+"狗狗并不愿放你走。";
                }
                child = new YourSkill(player);
                break;
            case 2:
                yourShape = "布";
                if (computerShape.equals("石头")) {
                    endText = printWinMessage(yourShape, computerShape)+"但似乎狗狗并不愿放你走。";
                } else if (computerShape.equals("剪刀")) {
                    endText = printLoseMessage(yourShape, computerShape)+"狗狗得意地给了你一嘴巴子,生命值-1，示意继续。";
                } else {
                    endText = printTieMessage(yourShape)+"狗狗并不愿放你走。";
                }
                child = new YourSkill(player);
                break;
            case 3:
                endText = "你成功逃跑了。但是，由于你不认识路，你绕了一圈又回到了原地。";
                child=new HowOldAreYou(player);
                break;
        }
    }

}
class OpenBag extends CrazyDog{
    int len;
    public OpenBag(Player player) {
        super(player);
        this.eventName = "OpenBag";
        this.happenText = "你要使用哪个道具？”";


        if (player.itemList.size()>=5) {
            options = new String[5];
            len = options.length;
        }
        else {
            options = new String[player.itemList.size()];
            len = options.length;
        }
        for (int i = 0; i < options.length; i++) {//player.foods.size()
            options[i]=player.itemList.get(i).getName();
        }
//        if (player.itemList.size()>5)
//            for (int i = 0;i < player.itemList.size()/5+1;i++){
//                for (int j = 0; j < 5; j++) {
//                    String[] optionsTwo = new String[6];
//                    optionsTwo[j]=player.itemList.get(j).getName();
//                    optionsTwo[5]=
//                    if (i==options.length)
//                }
//            }
    }
    public void eventHappen(int option) {
        switch (player.itemList.get(option).getName()) {
            //player.itemList.get(option);
            case "红白球":
                endText = "你把红白球扔向了狗狗，随着一道彩光，狗狗被球吸了进去，球晃了几下之后，你捕获成功了！你获得了道具”瘦弱的狗子“。";
                Item item = new Item("瘦弱的狗子");
                player.itemList.add(item);
                break;
            case "可能是狩猎球":
                endText = "旁边冒出一只屎壳郎，说道：“这是我滚的粪球”，你拿着我的粪球干嘛？狗子一听，面目更狰狞了，向你扑了过来，生命-2。.....你被送到了一个没听过的私立医院，躺了好1天。一段时间过后，你饿了,出来觅食。";
                player.setHealth(player.getHealth() - 2);
                child = new HowOldAreYou(player);
                break;
            default:
                endText ="这个有什么用";
                child = new CrazyDog(player);
                break;
        }

    }
}